package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级管理")
public class NursingLevelController {

    @Autowired
    private NursingLevelService nursingLevelService;

    @GetMapping("/listAll")
    @ApiOperation("查询所有护理等级")
    public ResponseResult<List<NursingLevelVo>> listAll(){
        log.info("查询所有护理等级");
        List<NursingLevelVo> list=nursingLevelService.listAll();

        return ResponseResult.success(list);
    }

    @PostMapping("/insert")
    @ApiOperation("新增护理等级")
    public ResponseResult insert(@RequestBody NursingLevelDto nursingLevelDto){
        log.info("新增护理等级,{}",nursingLevelDto);
        nursingLevelService.insert(nursingLevelDto);

        return ResponseResult.success();
    }

    @GetMapping("/listByPage")
    @ApiOperation("分页查询护理等级")
    public ResponseResult<PageResponse<NursingLevelVo>> listByPage(@ApiParam(value = "等级名称") String name,
                                                                   @ApiParam(value = "状态：0-禁用，1-启用")  Integer status,
                                                                   @ApiParam(value = "当前页码") @RequestParam(defaultValue = "1",required = false)Integer pageNum,
                                                                   @ApiParam(value = "每页数量") @RequestParam(defaultValue = "10",required = false)Integer pageSize){

        log.info("分页查询护理等级,{},{},{},{}",name,status,pageNum,pageSize);
        PageResponse<NursingLevelVo> result =nursingLevelService.listByPage(name,status,pageNum,pageSize);

        return ResponseResult.success(result);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询")
    public ResponseResult<NursingLevelVo> searchById(
                                            @ApiParam(value = "项目等级id",required = true) @PathVariable Integer id){
        log.info("根据id查询,{}",id);
        NursingLevelVo result =nursingLevelService.searchById(id);

        return ResponseResult.success(result);
    }

    @PutMapping("/update")
    @ApiOperation("修改项目等级")
    public ResponseResult update(@RequestBody NursingLevelDto nursingLevelDto){
        log.info("修改项目等级,{}",nursingLevelDto);
        nursingLevelService.update(nursingLevelDto);

        return ResponseResult.success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除项目等级")
    public ResponseResult deleteById(@ApiParam(value = "项目等级id",required = true) @PathVariable Integer id){
        log.info("删除项目等级,{}",id);
        nursingLevelService.deleteById(id);

        return ResponseResult.success();
    }

    @PutMapping("{id}/status/{status}")
    @ApiOperation("项目等级的启用和禁用")
    public ResponseResult idAndStatus(@ApiParam(value = "状态，0：禁用，1：启用",required = true) @PathVariable Integer status,
                                      @ApiParam(value = "护理等级ID",required = true) @PathVariable Integer id){
        log.info("项目等级的启用和禁用,{},{}",status,id);
        nursingLevelService.idAndStatus(id,status);

        return ResponseResult.success();
    }

}
